<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ include file="/jsp/common/common.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="keywords" content="jquery,ui,easy,easyui,web">
<meta name="description"
	content="easyui help you build your web page easily!">
<title>收银界面</title>
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui-1.5.3/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui-1.5.3/themes/icon.css"/>">
<link rel="stylesheet"
	href="<c:url value="/jsp/cashier/css/jquery-accordion-menu.css"/>">
<!-- CSS reset -->
<link rel="stylesheet"
	href="<c:url value="/css_font/fonts/iconfont.css"/>">
<link rel="stylesheet"
	href="<c:url value="/jsp/cashier/css/style.css"/>">
<!-- Resource style -->
<!-- Modernizr -->

<script type="text/javascript"
	src="<c:url value="/jsp/cashier/js/jquery-1.11.2.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/jsp/cashier/js/keyboard.js"/>"></script>

<script src="<c:url value="/jsp/cashier/js/jquery-accordion-menu.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui-1.5.3/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/common.js"/>"></script>

<script type="text/javascript"
	src="<c:url value="/jsp/cashier/jquery.numpad.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/LodopFuncs.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/jsp/cashier/js/weixinsaoma.js"/>"></script>

<style type="text/css">
.content {
	position: fixed;
	left: 0;
	top: 0;
	background: #ED5565;
	width: 12%;
	height: 100%;
	margin-top: 0px;
	margin-left: 0px;
	padding: 0px 10px;
	overflow-y: scroll;
}

#divForAddFoodType {
	position: fixed;
	left: 30%;
	top: 50px;
	width: 40%;
	background: #d4dddd;
	border-radius: 5px;
}

#divForWeixin {
	position: fixed;
	left: 30%;
	top: 50px;
	width: 40%;
	background: red;
	border-radius: 5px;
}

#divForAddFood {
	position: fixed;
	left: 30%;
	top: 50px;
	width: 40%;
	background: #d4dddd;
	border-radius: 5px;
}

#guadan_init {
	position: fixed;
	left: 30%;
	top: 50px;
	width: 40%;
	height: 300px;
	background: #d4dddd;
	border-radius: 5px;
}

#qudan_init {
	position: fixed;
	left: 30%;
	top: 50px;
	width: 40%;
	height: 90%;
	background: #d4dddd;
	border-radius: 5px;
}

#receipt_init {
	position: fixed;
	left: 10%;
	top: 50px;
	width: 80%;
	height: 500px;
	background: #FFF;
	border-radius: 5px;
	padding: 0 0 0 0;
}

.filterinput {
	margin-top: 8px;
	background-color: rgba(249, 244, 244, 0);
	border-radius: 15px;
	width: 90%;
	height: 30px;
	border: thin solid #FFF;
	text-indent: 0.5em;
	font-weight: bold;
	color: #FFF;
}

#demo-list a {
	overflow: hidden;
	text-overflow: ellipsis;
	-o-text-overflow: ellipsis;
	white-space: nowrap;
	width: 100%;
}

.products {
	list-style: none;
	margin-right: 10px;
	padding: 0px;
	height: 100%;
	text-align: center;
}

.products li {
	display: block;
	width: 230px;
	float: left;
	margin: 10px;
	background: #FFF;
	border-color: #f1f5ee;
	border: 4px solid #FFF;
}

.item {
	display: block;
	text-decoration: none;
}

.item img {
	border: 0px solid #333;
	border-color: #FFFFFF;
	width: 200px;
	height: 200px;
}

.item p {
	cursor: pointer;
	margin: 0;
	font-weight: bold;
	text-align: center;
	color: #000000;
}

.cart {
	position: fixed;
	right: 0;
	top: 0;
	width: 20%;
	height: 100%;
	background: #ccc;
	padding: 0px 10px;
	padding: 0px;
}

.looktype {
	position: fixed;
	left: 0;
	top: 0;
	width: 20%;
	height: 100%;
	background: #ccc;
	padding: 0px 10px;
}

.look1 {
	position: fixed;
	left: 12%;
	top: 0;
	width: 68%;
	height: 100%;
	padding: 0px 10px;
	overflow-y: scroll;
	background: #FFF;
}

h1 {
	text-align: center;
	color: #555;
}

.shoukuan {
	position: fixed;
	right: 0;
	bottom: 0;
	width: 20%;
	height: 50px;
	padding: 0px 10px;
	padding: 0px;
	font-size: 16px;
}

.cart_qingkong {
	position: fixed;
	right: 0;
	bottom: 50px;
	width: 20%;
	height: 50px;
	padding: 0px 10px;
	padding: 0px;
	font-size: 16px;
}

.cart_qudan {
	position: fixed;
	right: 0;
	bottom: 50px;
	width: 20%;
	height: 50px;
	padding: 0px 10px;
	padding: 0px;
	font-size: 16px;
}

h3 {
	font-size: 16px;
	margin-left: 10px;
	color: #555;
}

.total {
	text-align: left;
}


.zhou{float:left; width: 70%}
.zhou2{float:left; width: 20%}

.search-btn{margin-top: 9px;display:inline-block;cursor: pointer;
 width:25px;height:25px;background:url(<c:url value="/images/cashier/seach-icon.png"/>);background-size: 100%;}
</style>
<script>

    function prn1_view() {
        LODOP = getLodop();
        LODOP.PRINT_INIT("打印控件功能演示_Lodop功能_整页表格");
        LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A4");
        //alert(document.getElementById("listDisplay"));
        //LODOP.ADD_PRINT_TABLE("2%","1%","96%","98%",document.getElementById("listDisplay").innerHTML);
        var tableString = getPrnStr();
        //LODOP.ADD_PRINT_IMAGE(0,0,'100%','100%',"<img  border='0' style='z-index: -1; position: absolute;' src='../images/seal/caigouzhang2.png'/>");
        LODOP.ADD_PRINT_TABLE('5px', '2px', '95%', '94%', tableString);

        LODOP.SET_PREVIEW_WINDOW(0, 0, 0, 800, 600, "");
        //LODOP.PREVIEW();
        LODOP.PRINT();

    }
    function getPrnStr() {
        var rows = $('#cartcontent').datagrid('getRows');

        var tableStr;
        tableStr = "<table  style='border-collapse: collapse; border: 0px solid black;'>"
        //设置公司标题
        tableStr = tableStr + "<tr>";
        tableStr = tableStr
                + "<td colspan='4' align='center' style='font-size:14px;border-style:dashed;border-width:0px;height:30px;width:300px;'>"
                + "${shopPo.shopName }" + "</td>";

        tableStr = tableStr + "</tr>";
        //订单号 和日期
        tableStr = tableStr + "<tr>";
        tableStr = tableStr
                + "<td colspan='4' align='right' style='font-size:9px;border-style:dashed;border-width:0px;height:5px;width:300px;'>"
                 +getNowFormatDate() + "</td>";

        tableStr = tableStr + "</tr>";

        //设置列表属性
        tableStr = tableStr + "<tr>";
        tableStr = tableStr 
                + "<td style='font-size:10px;border-style:solid;border-width:0px;width:40px';>数量</td>";
        tableStr = tableStr
                + "<td style='font-size:10px;border-style:solid;border-width:0px;width:140px'>商品</td>";
        tableStr = tableStr
                + "<td style='font-size:10px;border-style:solid;border-width:0px;width:60px;'>单价</td>";
        tableStr = tableStr
                + "<td style='font-size:10px;border-style:solid;border-width:0px;width:60px'>总价</td>";
       
        tableStr = tableStr + "</tr>";
        var date;
        for (var i = 0; i < rows.length; i++) {
            tableStr = tableStr + "<tr>";
            tableStr = tableStr
                    + "<td style='font-size:10px;border-style:dashed;border-width:0px;border-top-width: 1px;'>"
                    + rows[i]['number'] + "</td>";
            tableStr = tableStr
                    + "<td style='font-size:10px;border-style:dashed;border-width:0px;border-top-width: 1px;'>"
                    + rows[i]['foodName'] + "</td>";
            tableStr = tableStr
                    + "<td style='font-size:10px;border-style:dashed;border-width:0px;border-top-width: 1px;'>￥"
                    + rows[i]['foodValue'] + "</td>";
            tableStr = tableStr
                    + "<td style='font-size:10px;border-style:dashed;border-width:0px;border-top-width: 1px;'>￥"
                    + rows[i]['foodValueAll'] + "</td>";
            tableStr = tableStr + "</tr>";
            
        }
        tableStr = tableStr + "<tr>";
        tableStr = tableStr
                + "<td colspan='3' align='right' style='font-size:10px;border-style:solid;border-width:0px;'>合计:</td>";
        tableStr = tableStr
                + "<td colspan='1' align='left' style='font-size:10px;border-style:solid;border-width:0px;'>￥"+ $('#write1').html()+"</td>";
        tableStr = tableStr + "</tr>"; 
        tableStr = tableStr + "</table>";

        return tableStr;
    }

    var cartId = 0;//设置默认单号 
	var data = {
		"total" : 0,
		"rows" : []
	};
    
    function init_qudanTable(){
    	$('#getOrderTable').datagrid({
            url : "<c:url value='/food/getShoppingCartOrderTable.do'/>",
            singleSelect : true,
            fitColumns:false
        });
    }
    
    function visitSession(){
        $.ajax({
            async : false,
            url : "<c:url value='/user/userTestValue.do'/>",
            type : "post",
            success : function(data) {
            }
        });
    }
    
	$(function() {
		$('#print_xiaopiao').switchbutton({ 
			onText:"是",
			offText:"否",
		    checked: true, 
		    onChange: function(checked){ 
		        
		    } 
		}) 
		setInterval("visitSession()", "200000");
        document.getElementById('divForAddFoodType').style.display = 'none';
        document.getElementById('divForAddFood').style.display = 'none';
        document.getElementById('receipt_init').style.display = 'none';
        document.getElementById('guadan_init').style.display = 'none';
        document.getElementById('qudan_init').style.display = 'none';
        document.getElementById('zhezhao2').style.display = 'none';
        document.getElementById('divForWeixin').style.display = 'none';
		$('#cartcontent').datagrid({
			url : "<c:url value='/food/findShoppingCartCashier.do'/>",
			singleSelect : true,
			fitColumns:false,
			onLoadSuccess:function(data){ 
                //收款额
                $('div.cart .total').html('￥' + data.totalValue); 
                $('#write1').html(data.totalValue);

                //挂单样式
                var rows = $('#cartcontent').datagrid('getRows');  
                if(rows.length>0){
                	$('#cart_qingkong').css('display','');
                    $('#cart_qudan').css('display','none');
                    cartId =rows[0]['cartId'];
                }else{
                	cartId=0;
                	//查询挂单数量
                	var orderNumber =getCartOrderNumber();
                    $('div.cart .qudan_number').html(orderNumber);

                    $('#cart_qingkong').css('display','none');
                	$('#cart_qudan').css('display','');
                }
                
                //取单后 的设置变换挂单 按钮样式
                if(cartId!=0||cartId!='0'){
                    $('#guadan_button').html('单号：'+cartId);
                    
                    $("#guadan_button").attr('onclick','').click( 
                            eval(
                                function(){
                                	document.getElementById('zhezhao').style.display = 'none';
                                    document.getElementById('guadan_init').style.display = 'none';
                                }
                            )
                        ); 
                }else{
                    $('#guadan_button').html('挂单');
                    $("#guadan_button").attr('onclick','').click( 
                    	eval(
                    		function(){
                    			document.getElementById('zhezhao').style.display = '';
                    	        document.getElementById('guadan_init').style.display = '';
                    		}
                    	)
                    ); 

                }
            },
            onClickCell:function(index, field, value){
            	
            	if(field == 'button'){
            		var rows = $('#cartcontent').datagrid('getRows');
            		var row = rows[index];
            		var foodId = row.foodId;
            		deleteCartOne(foodId);
            	}
            }
		});
		
		$('.item').draggable({
			revert : true,
			proxy : 'clone',
			onStartDrag : function() {
				$(this).draggable('options').cursor = 'not-allowed';
				$(this).draggable('proxy').css('z-index', 10);
			},
			onStopDrag : function() {
				$(this).draggable('options').cursor = 'move';
			}
		});
		$('.cart').droppable({
			onDragEnter : function(e, source) {
				$(source).draggable('options').cursor = 'auto';
			},
			onDragLeave : function(e, source) {
				$(source).draggable('options').cursor = 'not-allowed';
			},
			onDrop : function(e, source) {
				var name = $(source).find('p:eq(0)').html();
				var price = $(source).find('p:eq(1)').html();
				addProduct(name, parseFloat(price.split('$')[1]));
			}
		});
        document.getElementById('initzhezhao').style.display = 'none';

	});
	//滚动检索
	function searchType(foodtypeId) {
		var topvalue = $('.look1').scrollTop();
		var pos = $('#foodType'+foodtypeId).position().top + topvalue;
		$('.look1').animate({
			scrollTop : pos
		}, 300);
	}

	jQuery(document).ready(function() {
		jQuery("#jquery-accordion-menu").jqueryAccordionMenu();

	});

	
	function getCartOrderNumber(){
		var returnValue;
		
		var dataOneJson;
        var dateone;
        dateone = '{}';
        dataOneJson =JSON.parse(dateone);
        $.ajax({
            async : false,
            url : "<c:url value='/food/getCartOrderNumber.do'/>" ,
            type : "post",
            dataType: "json",
            data: $.param(dataOneJson),
            success : function(data) {
                if(typeof(data)=='string'){
                    dataJson =JSON.parse(data);
                }else{
                    dataJson = data;
                }
                if(dataJson.success){
                	returnValue = dataJson.orderNumber;
                }else{
                }
            }
        });
        return returnValue;
	}
	
	$(function() {
		//顶部导航切换
		$("#demo-list li").click(function() {
			$("#demo-list li.active").removeClass("active")
			$(this).addClass("active");
		})
	})
	
	function addShopping(foodId,foodName,foodValue){
		var dataOneJson;
        var dateone;
        dateone = '{"cartId":"'+ cartId +'","foodId":"'+ foodId+'","number":"1","foodValue":"' + foodValue+'","foodName":"'+ foodName+'"}';
        dataOneJson =JSON.parse(dateone);
		$.ajax({
            async : true,
            url : "<c:url value='/food/addShoppingCart.do'/>" ,
            type : "post",
            dataType: "json",
            data: $.param(dataOneJson),
            success : function(data) {
                if(typeof(data)=='string'){
                    dataJson =JSON.parse(data);
                }else{
                    dataJson = data;
                }
                if(dataJson.success){
                	$('#cartcontent').datagrid('load', {
                        cartId : cartId
                    }); 
                }else{
                   /*  $.messager.alert('提示','购物车已有此种商品，请在购物车中修改数量！','info'); */
                }
            }
        });
		
	}
	
	
	function addFoodType(){
	    document.getElementById('zhezhao').style.display = '';
		document.getElementById('divForAddFoodType').style.display = '';
		
	}
	function addFoodTypeCommit(){
		var foodTypeName = document.getElementById('foodTypeName').value;
        if(foodTypeName== null ||foodTypeName==''||foodTypeName== undefined){
            alert("不能为空！");
            return;
        }
        var form = new FormData();
        //ajax 提交表单数据
        form.append("foodTypeName", foodTypeName); // 可以增加表单数据
        // XMLHttpRequest 对象
        xhr = new XMLHttpRequest();
        xhr.open("post", '<c:url value='/food/addFoodType.do'/>', true);
        xhr.onload = function(a) {
        	document.getElementById('foodTypeName').value="";
            window.location.reload();
        }; 
        xhr.send(form);
    }
	function addFoodTypeCancel(){
        $('#foodTypeName').textbox("setValue","");
        document.getElementById('zhezhao').style.display = 'none';
        document.getElementById('divForAddFoodType').style.display = 'none';
    }
	function formatOptionField(val,rowData,rowIndex){
        return "<a href='###'><img src='../images/edit_remove.png'/></a>";
    }
	
	function addFood(foodTypeId,foodTypeName){
        $('#foodTypeName2').textbox("setValue",foodTypeName);
        $('#foodType').textbox("setValue",foodTypeId);
		document.getElementById('zhezhao').style.display = '';
        document.getElementById('divForAddFood').style.display = '';
	}
	function addFoodCancel(){
        $('#foodTypeName2').textbox("setValue","");
        $('#foodType').textbox("setValue","");
        $('#foodName').textbox("setValue","");

        document.getElementById('zhezhao').style.display = 'none';
        document.getElementById('divForAddFood').style.display = 'none';
    }
	function addFoodCommit(){
        $('#divForAddFoodFrom').form('submit', {
            url : '<c:url value='/food/addFoodForCashier.do'/>', //查询提交路径
            onSubmit : function()//提交按钮相应函数
            {
                return $('#divForAddFoodFrom').form('validate');
            },
            success : function(data) {
                data = eval('(' + data + ')');
                if (data.success) {
                	$('#foodTypeName2').textbox("setValue","");
                    $('#foodTypeId2').textbox("setValue","");
                    $('#foodName').textbox("setValue","");
                    window.location.reload();
                } else {
                    $.messager.alert("提示", data.msg, 'warning');
                }
            },
            error : function() {
                $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
                return;
            }
        });
    }
	
	function nofindPhoto(id){
		
		var img=document.getElementById(id);
		//img.src="http://localhost:8080/appidnitjb322b2/jsp/cashier/images/shirt1.gif";
		img.src="http://localhost:8080/appidnitjb322b2/images/zanwutupian.jpg";
		
		img.onerror=null; 
		//img.style.display = 'none';
	}
	function shoukuan(){
		//失去焦点
		//$('#search').focus();
		var rows = $('#cartcontent').datagrid('getRows');
		if(rows.length >0){
			$('#write').html('');
	        $('#write2').html('');
	        document.getElementById('zhezhao').style.display = '';
	        document.getElementById('receipt_init').style.display = '';
		}else{
			alert("购物车中没有商品！");
		}
	}
	function receipt_init_close(){
		document.getElementById('zhezhao').style.display = 'none';
        document.getElementById('receipt_init').style.display = 'none';
	}
	function deleteCartAll(){
		var dataOneJson;
        var dateone;
        dateone = '{"cartId":"'+ cartId +'"}';
        dataOneJson =JSON.parse(dateone);
		$.ajax({
            async : false,
            url : "<c:url value='/food/deleteShoppingCart.do'/>" ,
            type : "post",
            dataType: "json",
            data: $.param(dataOneJson),
            success : function(data) {
                if(typeof(data)=='string'){
                    dataJson =JSON.parse(data);
                }else{
                    dataJson = data;
                }
                if(dataJson.success){
                	cartId =0;
                   $('#cartcontent').datagrid('reload');
                }else{
                   /*  $.messager.alert('提示','购物车已有此种商品，请在购物车中修改数量！','info'); */
                }
            }
        });
	}
	
	function deleteCartOne(foodId){
		var dataOneJson;
        var dateone;
        dateone = '{"foodId":"' + foodId + '","cartId":"' + cartId + '"}';
        dataOneJson =JSON.parse(dateone);
        $.ajax({
            async : false,
            url : "<c:url value='/food/deleteCartOne.do'/>" ,
            type : "post",
            dataType: "json",
            data: $.param(dataOneJson),
            success : function(data) {
                if(typeof(data)=='string'){
                    dataJson =JSON.parse(data);
                }else{
                    dataJson = data;
                }
                if(dataJson.success){
                   $('#cartcontent').datagrid('reload');
                }else{
                   /*  $.messager.alert('提示','购物车已有此种商品，请在购物车中修改数量！','info'); */
                }
            }
        });
	}
	function zhifubao(){
		alert("暂未开通！");
	}
	
	/* function guadan_init(){
        document.getElementById('zhezhao').style.display = '';
        document.getElementById('guadan_init').style.display = '';
	} */
	function addguadanCancel(){
		document.getElementById('zhezhao').style.display = 'none';
        document.getElementById('guadan_init').style.display = 'none';
	}
	var updateShoppingCartXhr;
	function addguadan(){
		var cartIdForm = document.getElementById('cartId').value;
        if(cartIdForm== null ||cartIdForm==''||cartIdForm== undefined){
            alert("单号不能为空！");
            return;
        }
        var form = new FormData();
        //ajax 提交表单数据
        form.append("cartId", cartIdForm); // 可以增加表单数据
        // XMLHttpRequest 对象
        updateShoppingCartXhr = new XMLHttpRequest();
        updateShoppingCartXhr.onreadystatechange = updateShoppingCart_return;
        updateShoppingCartXhr.open("post", '<c:url value='/food/updateShoppingCart.do'/>', true);
        updateShoppingCartXhr.send(form);
	}
	
	function updateShoppingCart_return() {
        if (updateShoppingCartXhr.readyState == 4) {// 4 = "loaded"

            if (updateShoppingCartXhr.status == 200) {// 200 = OK
                var data;
                data = updateShoppingCartXhr.responseText;
                if (typeof (data) == 'string' && data != '') {
                    data = JSON.parse(data);
                }
               if(data.success){
            	   document.getElementById('zhezhao').style.display = 'none';
                   document.getElementById('guadan_init').style.display = 'none';
                   $('#cartcontent').datagrid('reload');
               }else{
                   $.messager.alert("提示", data.msg, 'info');
               }
            } else {
                alert("Problem retrieving XML data");
            }
        }
    }
	function qudaninit(){
		document.getElementById('zhezhao').style.display = '';
        document.getElementById('qudan_init').style.display = '';
        init_qudanTable();
	}
	
	function qudan_cancel(){
		document.getElementById('zhezhao').style.display = 'none';
        document.getElementById('qudan_init').style.display = 'none';
	}
	function qudan_commit(){
		var row = $('#getOrderTable').datagrid('getSelections');
        if(row.length == 0){
            $.messager.alert('提示','请选择一条记录操作！','info');
            return;
        }else{
        	cartId = row[0]['cartId'];
        	$('#cartcontent').datagrid('load', {
                cartId : cartId
            }); 
        }
        $('#getOrderTable').datagrid('clearSelections');
        document.getElementById('zhezhao').style.display = 'none';
        document.getElementById('qudan_init').style.display = 'none';
    }
	var receipt_commit_xhr;
	function receipt_commit(flag_payWay){
		var form = new FormData();
        //ajax 提交表单数据
        form.append("cartId", cartId); // 可以增加表单数据
        form.append("payWay", flag_payWay); // 可以增加表单数据

        form.append("foodValueAllCheck", $('#write1').html()); // 可以增加表单数据
        
        // XMLHttpRequest 对象
        receipt_commit_xhr = new XMLHttpRequest();
        receipt_commit_xhr.onreadystatechange = receipt_commit_return;
        receipt_commit_xhr.open("post", '<c:url value='/food/receiptCommit.do'/>', true);
        receipt_commit_xhr.send(form);
	}
	function receipt_commit_return() {
        if (receipt_commit_xhr.readyState == 4) {// 4 = "loaded"

            if (receipt_commit_xhr.status == 200) {// 200 = OK
                var data;
                data = receipt_commit_xhr.responseText;
                if (typeof (data) == 'string' && data != '') {
                    data = JSON.parse(data);
                }
               if(data.success){
                   
                   
                   //判断是否打印小票
                   if($("#print_xiaopiao").switchbutton("options").checked){
                      prn1_view();
                   } 
                   cartId=0;
                   $('#cartcontent').datagrid('load', {
                       cartId : cartId
                   }); 
                   document.getElementById('zhezhao').style.display = 'none';
                   document.getElementById('receipt_init').style.display = 'none';
                   
               }else{
                   $.messager.alert("提示", data.msg, 'info');
               }
            } else {
                alert("Problem retrieving XML data");
            }
        }
    }
	function weixin_init(){
		
		document.getElementById('zhezhao2').style.display = '';
        document.getElementById('divForWeixin').style.display = '';
        $('#quickMark').val("");
        $('#quickMark').focus();

	}
	var weixin_commit_xhr;
	function weixin_commit(){
		var form = new FormData();
        //ajax 提交表单数据
        form.append("cartId", cartId); // 可以增加表单数据
        form.append("payWay", 1); // 可以增加表单数据
        form.append("auth_code", document.getElementById("quickMark").value);
        form.append("htmlValue", $('#write1').html()); // 可以增加表单数据
        
        // XMLHttpRequest 对象
        weixin_commit_xhr = new XMLHttpRequest();
        weixin_commit_xhr.onreadystatechange = weixin_commit_return;
        weixin_commit_xhr.open("post", '<c:url value='/weixinpay/weixinpay.do'/>', true);
        weixin_commit_xhr.send(form);
	}
	function weixin_commit_return(){
		if (weixin_commit_xhr.readyState == 4) {// 4 = "loaded"
            if (weixin_commit_xhr.status == 200) {// 200 = OK
                var data;
                data = weixin_commit_xhr.responseText;
                if (typeof (data) == 'string' && data != '') {
                    data = JSON.parse(data);
                }
               if(data.success){
                   alert("微信支付成功！");
                   //判断是否打印小票
                   if($("#print_xiaopiao").switchbutton("options").checked){
                      prn1_view();
                   } 
                   cartId=0;
                   $('#cartcontent').datagrid('load', {
                       cartId : cartId
                   });
                   document.getElementById('zhezhao2').style.display = 'none';
                   document.getElementById('divForWeixin').style.display = 'none';
                   document.getElementById('zhezhao').style.display = 'none';
                   document.getElementById('receipt_init').style.display = 'none';
                   
                   $('#quickMark').val("");
               }else{
                   $.messager.alert("提示", data.msg, 'info');
               }
            } else {
                alert("Problem retrieving XML data");
            }
        }
	}
	function search_food(){
		var element_div = document.getElementById("look1");  
        element_div.innerHTML ="";
        var tableul ='<ul class="products">';
		
		var foodName = document.getElementById("search_food_id").value;
		var dataOneJson;
        var dateone;
        dateone = '{"foodName":"' + foodName + '"}';
        dataOneJson =JSON.parse(dateone);
        $.ajax({
            async : false,
            url : "<c:url value='/food/searchFood.do'/>" ,
            type : "post",
            dataType: "json",
            data: $.param(dataOneJson),
            success : function(data) {
                if(typeof(data)=='string'){
                    dataJson =JSON.parse(data);
                }else{
                    dataJson = data;
                }
                if(dataJson.success){
                	var foodList =dataJson.foodListForSearch;
                	for (x in foodList)
                	{
                	 tableul =tableul+
                    '<li onmouseout="this.style.border=\'4px solid #FFF\'"' +
                        ' onmouseover="this.style.border=\'4px solid red\'">' +
                        ' <a style="border: 1px solid #f1f5ee; padding: 5px;" href="#" class="item"'+
                        ' onclick="addShopping(\''+foodList[x].foodId+'\',\''+foodList[x].foodName+'\',\''+foodList[x].foodValue+'\')">'+
                            ' <img style="cursor: pointer;" onerror="nofindPhoto(\''+foodList[x].foodId+'\');" id="'+foodList[x].foodId+'" src="<c:url value="/jsp/ui/mid/'+foodList[x].foodId+'.jpg"/>" />'+
                            ' <div>'+
                                '<p style="color: red;">￥'+foodList[x].foodValue+'</p>'+
                                //'<p style="color: red;">￥${food.foodValue }</p>'+
                                '<p>'+foodList[x].foodName+'</p>'+
                                //'<p>${food.foodName }</p>'+
                            ' </div>'+
                    ' </a></li>'; 
                	}
                	
                    
                    tableul = tableul+' </ul>';
                    element_div.innerHTML =tableul;
                	
                } 
            }
        });
	}
	
	function search_food_all(){
        
        var element_div = document.getElementById("look1");  
        var tableul ='<table>';

        var element_demo_list = document.getElementById("demo-list");  
        var ul_demo_list =' ';
        
        var foodName = document.getElementById("search_food_id").value;
        var dataOneJson;
        var dateone;
        dateone = '{"foodName":"' + foodName + '"}';
        dataOneJson =JSON.parse(dateone);
        $.ajax({
            async : false,
            url : "<c:url value='/food/searchFoodDetail.do'/>" ,
            type : "post",
            dataType: "json",
            data: $.param(dataOneJson),
            success : function(data) {
                if(typeof(data)=='string'){
                    dataJson =JSON.parse(data);
                }else{
                    dataJson = data;
                }
                if(dataJson.success){
                    var foodTypeCashier = dataJson.rows;
                    for (a in foodTypeCashier){
                    	tableul=tableul+'<tr><td>';
                        tableul=tableul+'<p class="'+foodTypeCashier[a].classType+'" id="'+foodTypeCashier[a].htmlFoodtypeId+'">';
                        tableul=tableul+' &nbsp '+foodTypeCashier[a].foodTypeName + ' &nbsp';
                        tableul=tableul+' <ul class="products">';

                        var foodList =foodTypeCashier[a].foodVolist;

                        for (x in foodList)
                        {
                         tableul =tableul+
                        '<li onmouseout="this.style.border=\'4px solid #FFF\'"' +
                            ' onmouseover="this.style.border=\'4px solid red\'">' +
                            ' <a style="border: 1px solid #f1f5ee; padding: 5px;" href="#" class="item"'+
                            ' onclick="addShopping(\''+foodList[x].foodId+'\',\''+foodList[x].foodName+'\',\''+foodList[x].foodValue+'\')">'+
                                ' <img style="cursor: pointer;" onerror="nofindPhoto(\''+foodList[x].foodId+'\');" id="'+foodList[x].foodId+'" src="<c:url value="/jsp/ui/mid/'+foodList[x].foodId+'.jpg"/>" />'+
                                ' <div>'+
                                    '<p style="color: red;">￥'+foodList[x].foodValue+'</p>'+
                                    //'<p style="color: red;">￥${food.foodValue }</p>'+
                                    '<p>'+foodList[x].foodName+'</p>'+
                                    //'<p>${food.foodName }</p>'+
                                ' </div>'+
                        ' </a></li>'; 
                        }
                    	
                    	
                        tableul = tableul+' </ul>';

                        tableul=tableul+'</tr></td>';
                    }
                    tableul=tableul+'</table>';

                    element_div.innerHTML =tableul;
                    //检索 商品种类div
                    var rowsFoodType = dataJson.rowsFoodType;
                    for (b in rowsFoodType){
                            ul_demo_list =ul_demo_list+'<li><a href="#" onclick="searchType('+rowsFoodType[b].foodTypeId +');"><i class="'+rowsFoodType[b].classType+'"></i>'+rowsFoodType[b].foodTypeName +' <//a><//li>';
                    }
                    ul_demo_list =ul_demo_list+'<li><a id=\'a_foodType\' href="#" onclick="addFoodType();" style="background: #2543b4;" onmouseout="this.style.backgroundColor=\'#2543b4\'" onmouseover="this.style.backgroundColor=\'#3ccbef\'"><i></i>新增种类</a></li>';
                    element_demo_list.innerHTML =ul_demo_list;
                }
            }
        });
    }
	function search_onkeyUp(){
		if($("#search_food_id").val()==''){
			search_food_all();
		}
	}
</script>
</head>
<body style="margin: 0; padding: 0; height: 100%; background: #fafafa;">
	<div id="initzhezhao"
		style="z-index: 99; width: 100%; height: 100%; position: fixed; top: 0px; background-color: #FFF; text-align: center;">
	</div>
	<div class="content">
		<div id="jquery-accordion-menu" class="jquery-accordion-menu red">
			<div class="jquery-accordion-menu-header" id="form">
			    <div class="zhou">
                    <input id='search_food_id' onKeyUp="search_onkeyUp()" type="text" width="50px" placeholder="搜索" class="filterinput" />
                </div>
                <div class="zhou2">
                    <span class="search-btn" onclick="search_food_all()"></span>
                </div>
			</div>
			<ul id="demo-list">
				<c:forEach var="foodType" items="${rowsFoodType}" varStatus="st">
					<li><a href="#" onclick="searchType(${foodType.foodTypeId });"><i
							class="${foodType.classType}"></i>${foodType.foodTypeName } </a></li>
				</c:forEach>
				<li><a id='a_foodType' href="#" onclick="addFoodType();"
					style="background: #2543b4;"
					onmouseout="this.style.backgroundColor='#2543b4'"
					onmouseover="this.style.backgroundColor='#3ccbef'"><i></i>新增种类
				</a></li>
			</ul>
			<!-- <div class="jquery-accordion-menu-footer" style="cursor: pointer;">新增种类</div> -->
		</div>
	</div>
	<div class="look1" id="look1">

		<table>
			<c:forEach var="foodTypeCashier" items="${rows}" varStatus="st">
				<tr>
					<td>
						<p class="${foodTypeCashier.classType} "
							id="${foodTypeCashier.htmlFoodtypeId }">
							&nbsp ${foodTypeCashier.foodTypeName } &nbsp<a
								href="javascript:void(0)" class="easyui-linkbutton" plain="true"
								outline="true"
								onclick="addFood('${foodTypeCashier.foodTypeId }','${foodTypeCashier.foodTypeName }')"
								style="width: 60px; height: 20px; background: #3ccbef; vertical-align: bottom;">新增商品</a>
						</p>
						<ul class="products">
							<c:forEach var="food" items="${foodTypeCashier.foodVolist}"
								varStatus="st">
								<li onmouseout="this.style.border='4px solid #FFF'"
									onmouseover="this.style.border='4px solid red'"><a
									style="border: 1px solid #f1f5ee; padding: 5px;" href="#"
									class="item"
									onclick="addShopping('${food.foodId }','${food.foodName }','${food.foodValue }')">
										<img style="cursor: pointer;"
										onerror="nofindPhoto('${food.foodId }');" id="${food.foodId }"
										src="<c:url value="/jsp/ui/mid/${food.foodId }.jpg"/>" />
										<div>
											<p style="color: red;">￥${food.foodValue }</p>
											<p>${food.foodName }</p>
										</div>
								</a></li>
							</c:forEach>
						</ul>
					</td>
				</tr>
			</c:forEach>
		</table>
	</div>
	<div class="cart">
		<h1>Shopping Cart</h1>
		<div style="background: #fff">
			<table id="cartcontent" fitColumns="false" fit="false" idField="cid"
				pagination="true" pageSize="10" pageList="[10,20,30,40,50,100]"
				style="width: 100%; height: auto;">
				<thead>
					<tr>
						<th field="cid" hidden="true">cid</th>
						<th field="cartId" hidden="true">cartId</th>
						<th field="foodId" hidden="true">id</th>
						<th field="button" width=10% formatter="formatOptionField"></th>
						<th field="foodName" width=35%>名称</th>
						<th field="number" width=20% align="right">数量</th>
						<th field="foodValue" width=20% align="right">单价</th>
						<th field="foodValueAll" width=20% align="right">总价</th>
					</tr>
				</thead>
			</table>
		</div>
		<div class="cart_qingkong" id="cart_qingkong"
			style="background: #95f640; font-size: 30px; cursor: pointer; display: none;">
			<table class='table_cart' border="0"
				style="height: 50px; width: 100%; color: #FFF;" cellspacing="0">
				<tr border="0">
					<td align="center" width="50%" height="50px" bgcolor='#80d535'
						onclick="deleteCartAll();">清空</td>
					<td id="guadan_button" align="center" width="50%" height="50px">挂单</td>
					<td></td>
				</tr>
			</table>
		</div>
		<div class="cart_qudan" id="cart_qudan"
			style="background: #95f640; font-size: 30px; cursor: pointer; display: none;"
			onclick="qudaninit();">
			<table style="height: 50px; width: 100%; color: #FFF;">
				<tr>
					<td align="right" width="55%">取单</td>
					<td align="left" class="qudan_number"
						style="font-size: 20px; color: red">0</td>
					<td></td>
				</tr>
			</table>
		</div>
		<div class="shoukuan"
			style="background: #ff5555; font-size: 30px; cursor: pointer;"
			onclick="shoukuan();">
			<table style="height: 50px; width: 100%; color: #FFF;">
				<tr>
					<td align="right">收款</td>
					<td align="left" class="total">￥0.00</td>
					<td></td>
				</tr>
			</table>
		</div>

		<!-- <h2>Drop here to add to cart</h2> -->
	</div>
	<div id="divForAddFoodType" class="easyui-navpanel"
		style="position: relative; padding: 20px; z-index: 11;">
		<form id="addFoodTypeFrom">
			<div style="margin-bottom: 10px; text-align: center;">
				<input class="easyui-textbox" id="foodTypeName"
					style="max-width: 200px; width: 50%;" label="新建分类名称:"
					prompt="新建分类名称:">
			</div>
			<div style="margin-bottom: 30px; text-align: center;">
				<a href="javascript:void(0)" class="easyui-linkbutton" plain="true"
					outline="true" onclick="addFoodTypeCommit()" style="width: 60px;">创建分类</a>
				<a href="javascript:void(0)" class="easyui-linkbutton" plain="true"
					outline="true" onclick="addFoodTypeCancel()" style="width: 60px;">取消</a>
			</div>
		</form>
	</div>
	<div id="divForWeixin"
		style="position: relative; padding: 20px; z-index: 20;">
		<div style="margin-bottom: 10px; text-align: center;">
			<font size="15px">请用扫码枪扫码！</font>
		</div>
		<div style="margin-bottom: 10px; text-align: center;">
			<input id="quickMark" name="quickMark"
				onKeyUp="SubmitKeyClickrepint(this,event,'OK')"
				style="display: table-cell; width: 80%; margin: 0; vertical-align: middle;"></input>
		</div>



	</div>
	<div id="divForAddFood" name="divForAddFood" class="easyui-navpanel"
		style="position: relative; padding: 20px; z-index: 11;">
		<form id="divForAddFoodFrom" name="divForAddFoodFrom" method="post"
			enctype="multipart/form-data">
			<div style="margin-bottom: 10px; text-align: center;">
				<input class="easyui-textbox" id="foodTypeName2"
					name="foodTypeName2" readonly="true"
					style="max-width: 200px; width: 50%;" label="新建分类名称:"
					prompt="新建分类名称:">
			</div>
			<div style="margin-bottom: 10px; text-align: center;">
				<input class="easyui-textbox" id="foodName" name="foodName"
					data-options="required:true" style="max-width: 200px; width: 50%;"
					label="商品名称:" prompt="商品名称:">
			</div>
			<div style="margin-bottom: 10px; text-align: center;">
				<input class="easyui-textbox" id="foodValue" name="foodValue"
					data-options="required:true" style="max-width: 200px; width: 50%;"
					label="售卖价:" prompt="售卖价:">
			</div>
			<div style="margin-bottom: 10px; text-align: center;">
				<input class="easyui-filebox" name="file"
					style="max-width: 200px; width: 50%;" prompt="上传图片"></input>
			</div>
			<div style="margin-bottom: 10px; text-align: center;">
				<a href="javascript:void(0)" class="easyui-linkbutton" plain="true"
					outline="true" onclick="addFoodCommit()" style="width: 60px;">确认</a>
				<a href="javascript:void(0)" class="easyui-linkbutton" plain="true"
					outline="true" onclick="addFoodCancel()" style="width: 60px;">取消</a>
			</div>
			<div style="margin-bottom: 10px; text-align: center; display: none;">
				<input class="easyui-textbox" type="hidden" id="foodType"
					name="foodType">
			</div>
		</form>
	</div>
	<div id="zhezhao"
		style="z-index: 10; width: 100%; height: 100%; position: fixed; top: 0px; background-color: #000; opacity: 0.3; text-align: center; display: none">
	</div>
	<div id="zhezhao2"
		style="z-index: 15; width: 100%; height: 100%; position: fixed; top: 0px; background-color: #000; opacity: 0.3; text-align: center; display: none">
	</div>
	<!-- 
	 收款弹出的窗口
	
	 -->
	<div id="receipt_init" name="" receipt_init"" class="easyui-navpanel"
		style="position: relative; z-index: 11; padding-top: 20px; padding-left: 20px;">

		<table width="100%" height="100%" style="margin: 0;">
			<tr>
				<td width="70%"
					style="text-align: center; border-right: 3px solid #73b7b8;">
					<div>
						<div style="margin-bottom: 10px; text-align: left; width: 100%;">
							<img style="margin: 0; height: 95px; vertical-align: middle;"
								src='../images/cashier/zonge.png' />
							<textarea readonly="true"
								style="display: table-cell; width: 80%; margin: 0; vertical-align: middle;"
								id="write1" name="write1"></textarea>
						</div>
						<div style="margin-bottom: 10px; text-align: left; width: 100%;">
							<img style="margin: 0; height: 95px; vertical-align: middle;"
								src='../images/cashier/xianjin.png' />
							<textarea readonly="true" id="write" name="write"
								style="display: table-cell; width: 80%; vertical-align: middle;"></textarea>
						</div>
						<div style="margin-bottom: 10px; text-align: left; width: 100%;">
							<img style="margin: 0; height: 95px; vertical-align: middle;"
								src='../images/cashier/zhaoling.png' />
							<textarea readonly="true" id="write2" name="write2"
								style="display: table-cell; width: 80%; vertical-align: middle;"></textarea>
						</div>
						<div style="margin-bottom: 10px; text-align: left; width: 100%;">
							<font size="3px" style="vertical-align: middle;">是否打印小票</font>&nbsp&nbsp&nbsp
							<input id='print_xiaopiao' class="easyui-switchbutton"
								style="vertical-align: middle;">
						</div>
						<div style="text-align: left;">
							<a onclick="receipt_commit(1)" class="super button red"
								style="vertical-align: middle;">确认</a> <a
								onclick="receipt_init_close();" class="super button yellow"
								style="margin-left: 20px; vertical-align: middle;">取消</a> <a
								href='###' onclick="zhifubao();"
								style="margin-left: 20px; vertical-align: middle;"><img
								style="vertical-align: middle; height: 70px; width: 70px;"
								src='../images/cashier/zhifubao.png' /></a> <a href='###'
								onclick="receipt_commit(2);"
								style="margin-left: 20px; vertical-align: middle;"><img
								style="vertical-align: middle; height: 70px; width: 70px;"
								src='../images/cashier/weixinzhifu.png' /></a>
						</div>
						<div style="text-align: center; display: none;">
							<input class="easyui-textbox" type="hidden" id="foodType"
								name="foodType">
						</div>
					</div>
				</td>
				<td width="30%" style="text-align: center;">
					<div id="container">
						<ul id="keyboard">
							<li class="symbol"><span class="off">1</span></li>
							<li class="symbol"><span class="off">2</span></li>
							<li class="symbol"><span class="off">3</span></li>
							<li class="symbol"><span class="off">4</span></li>
							<li class="symbol"><span class="off">5</span></li>
							<li class="symbol"><span class="off">6</span></li>
							<li class="symbol"><span class="off">7</span></li>
							<li class="symbol"><span class="off">8</span></li>
							<li class="symbol"><span class="off">9</span></li>
							<li class="symbol"><span class="off">0</span></li>
							<li class="point">.</li>
							<li class="delete lastitem">←</li>
						</ul>
					</div>
				</td>
			<tr>
		</table>
	</div>

	<!--  挂单页面 -->
	<div id="guadan_init" name="" receipt_init"" class="easyui-navpanel"
		style="position: relative; z-index: 11; padding-top: 20px; padding-left: 20px;">

		<div style="margin-bottom: 10px; text-align: center;">
			<input class="easyui-numberbox" id="cartId" name="cartId"
				validType="length[1,3]" style="max-width: 200px; width: 50%;"
				label="新建牌号:" prompt="新建牌号:">
		</div>

		<div style="margin-bottom: 10px; text-align: center;">
			<a href="javascript:void(0)" class="easyui-linkbutton" plain="true"
				outline="true" onclick="addguadan()" style="width: 60px;">确认</a> <a
				href="javascript:void(0)" class="easyui-linkbutton" plain="true"
				outline="true" onclick="addguadanCancel()" style="width: 60px;">取消</a>
		</div>
	</div>

	<!--  取单选择页面 -->
	<div id="qudan_init" name="" receipt_init"" class="easyui-navpanel"
		style="position: relative; z-index: 11; padding: 20px 20px 20px 20px;">
		<div>
			<table id="getOrderTable" fitColumns="false" fit="false"
				idField="cartId" pagination="true" pageSize="10"
				pageList="[10,20,30,40,50,100]" style="width: 70%; height: auto;">
				<thead>
					<tr>
						<th field="cartId" width="20%">单号</th>
						<th field="foodALL" width="80%">已下单商品</th>
					</tr>
				</thead>
			</table>
		</div>

		<div
			style="margin-bottom: 10px; text-align: left; margin-top: 20px; margin-bottom: 20px;">
			<a onclick="qudan_commit();" class="super button red"
				style="vertical-align: middle;">确认</a> <a onclick="qudan_cancel();"
				class="super button yellow"
				style="margin-left: 20px; vertical-align: middle;">取消</a>
		</div>
	</div>

	<object id="LODOP_OB"
		classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0>
		<embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0></embed>
	</object>
</body>
<script type="text/javascript">
	/* (function($) {
		$.expr[":"].Contains = function(a, i, m) {
			return (a.textContent || a.innerText || "").toUpperCase().indexOf(
					m[3].toUpperCase()) >= 0;
		};
		function filterList(header, list) {
			//@header 头部元素
			//@list 无需列表
			//创建一个搜素表单
			var form = $("<form>").attr({
				"class" : "filterform",
				action : "#"
			}), input = $("<input>").attr({
				"class" : "filterinput",
				type : "text",
				"id":"search"
			});
			$(form).append(input).appendTo(header);
			
		}
		$(function() {
			filterList($("#form"), $("#demo-list"));
		});
	})(jQuery); */

</script>
</html>